home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / diskmags / 0022-3.564 / dmg-3451 / data / musplay.dat < prev    next >
Text File  |  1987-04-21  |  8KB  |  305 lines

  1. Mad Max/Count Zero music player.
  2. Wheee the fibble.
  3.  
  4. Many's the time when I want to listen to some music before 
  5. including it in a program/screen whatever.  So, rather than exit 
  6. STOS and use someone elses player, I did a little one which you 
  7. could call from STOS.  It's now upto version 2.5, but I'm going to 
  8. re-write it this week so I'll give away this version this time and 
  9. I'll send the source to the new version into this mag as soon as I 
  10. can.  The basic principle of playing music from STOS is very 
  11. simple:
  12. Mad Max:
  13. (assuming you've loaded a mad max tune into a bank)
  14.  
  15. dreg(0) = music number : call start (bank) : wait vbl
  16. repeat : call start(back)+8 : wait vbl : until whatever
  17.  
  18. Count Zero:
  19. dreg(0) = music number : call start (bank)
  20. repeat : call start(back)+2 : wait vbl : until whatever
  21.  
  22. For Mad Max music the music number can be from 1 - 15, but it'll 
  23. usually just have one tune in it, and Count Zero is almost always 
  24. just set to 1.  This will only work if your program is updating at 
  25. 50 frames per socond of course, other wise it won't sound very 
  26. good at all.
  27.  
  28. So, here's my little music player... 
  29.  
  30. 50 on error goto 960
  31.  
  32.      Set up error trap.
  33.  
  34. 60 mode 0 : key off : hide : flash off : click off : curs off 
  35.  
  36.      Set up screen (no high res! 70hz is out!)
  37.  
  38. 65 ICE$="ICE!" : ICE=leek(varptr(ICE$))
  39.  
  40.      This string is always found at the beggining of ice-packed 
  41.      data files.  This justs sets up a variable to check for it.
  42.  
  43. 70 reserve as work 8,32 : reserve as work 9,32
  44.  
  45.      Reserve some memory for the rasters.
  46.  
  47. 80 reserve as work 13,34
  48.  
  49.      And some more memory for something else.
  50.  
  51. 90 reserve as work 10,30000
  52.  
  53.      Memory for the music file (if your music file is longer than 
  54.      30k, then there's probably something up...)
  55.  
  56. 130 DR=drive 
  57.  
  58.      Save old drive (ain't it a pain when a program leaves you on 
  59.      the wrong drive?)
  60.  
  61. 140 colour 0,0
  62. 150 colour 15,$777
  63.  
  64.      Set up paper+pen colours.
  65.  
  66. 160 pen 15
  67.  
  68.      Erm, set the pen to 15...
  69.  
  70. 170 show on 
  71.  
  72.      Mouse on.
  73.  
  74. 180 cls physic
  75. 190 cls back
  76. 200 cls logic : wait vbl 
  77.  
  78.      Clear all of the screens.
  79.  
  80. 220 cls physic,0,0,0 to 320,49
  81. 230 cls back,0,0,0 to 320,49 
  82. 240 cls logic,0,0,0 to 320,49
  83.  
  84.      Clear the top 50 pixels of each screen (dunno if this bit's 
  85.      still needed actually).
  86.  
  87. 250 for T=1 to 14
  88. 260 colour T,deek(start(13)+T*2)
  89. 270 next T
  90. 280 wait vbl
  91.  
  92.      Reset palette.
  93.  
  94. 290 centre "WHEEE THE FIBBLES MUSIC PLAYER. V2.5" : print 
  95. 300 F$=file select$("*.MUS","LOAD A .MUS FILE, RETURN TO QUIT",4) : rem> FILE <
  96. 310 curs off 
  97. 320 if F$="" then drive=DR : default : end : rem> EXIT <
  98.  
  99.      Get the filename.  If it's empty the exit.
  100.  
  101. 330 hide on 
  102.  
  103.      Mouse off.
  104.  
  105. 340 for T=0 to 14
  106. 350 colour T,0
  107. 360 next T
  108. 370 wait vbl 
  109.  
  110.      Black palette.
  111.  
  112.  
  113. 380 cls physic,0,0,0 to 320,49
  114. 390 cls back,0,0,0 to 320,49
  115. 400 cls logic,0,0,0 to 320,49
  116.  
  117.      Clear the top 50 pixels again (???)
  118.  
  119. 410 home 
  120. 420 print "LOADING..."
  121.  
  122.      Print a top-quality message.
  123.  
  124. 430 open in #1,F$
  125. 440 L=lof(#1) : rem> GET LENGTH OF FILE <
  126. 450 close #1
  127.  
  128.      Open the file and get it's length.
  129.  
  130. 460 if length(10)<>0 then fill start(10) to start(10)+length(10),0
  131.  
  132.      If the bank is there then clear it (hmmm...)
  133.  
  134. 470 bload F$,10
  135.  
  136.      Load the music file.
  137.  
  138. 475 if leek(start(10))=ICE then print "DEPACKING" 
  139.     : areg(0)=start(10) : dreg(0)=0 : call start(14)+28 
  140.     : L2=dreg(0) : if L2>L then L=L2
  141.  
  142.      Check if the file is pack-iced. If it is then de-pack it and 
  143.      set the file-length variable to the length of the packed 
  144.      file.
  145.  
  146. 480 PS=8 : FLS=true : FLS2=false : CV=8
  147.  
  148.      PS is the PoSition to jump to in the music file (8 for mad 
  149.      max and 2 for count zero)
  150.  
  151. 490 if (deek(start(10))<>$6000) or (deek(start(10)+4)<>$6000) 
  152.     or (deek(start(10)+8)<>$6000) then gosub 850 : if PS<0 then goto 170
  153.  
  154.      Is it mad max? If not then check if it's Count Zero.  I know 
  155.      that you can check by HUNTing for TFMX, but I find it's best 
  156.      to make sure the file's ok (or was it saved with the ultimate 
  157.      ripper???)
  158.  
  159. 530 CUR=1 
  160.  
  161.      Music number to start playing.
  162.  
  163. 540 cls physic,0,0,0 to 320,49
  164. 550 cls back,0,0,0 to 320,49
  165. 560 cls logic,0,0,0 to 320,49
  166.  
  167.      Clear top 50 pixels (again, maybe they're very dirty).
  168.  
  169. 570 fill start(8) to start(8)+length(8),0 : doke start(8)+8,$FFFF
  170. 580 for T=start(9) to start(9)+4 step 2 :  : doke T,50 : next T 
  171.     : doke start(9)+10,$FFFF : doke start(9)+6,49 : doke start(9)+8,1
  172.  
  173.      Set up the rasters (I won't bother explaining it...)
  174.  
  175. 590 dreg(0)=CUR : call start(10)
  176.  
  177.      Initialise the music.
  178.  
  179. 600 home 
  180. 610 pen 15
  181. 620 centre "PLAYING MUSIC NUMBER"+str$(CUR)+" " : print 
  182. 630 centre "USE FUNCTION KEYS TO CHANGE MUSIC" : print 
  183. 640 centre "SPACE TO LOAD ANOTHER" : print 
  184. 650 centre "FILE: "+(F$-".MUS")+"   SIZE:"+str$(L) : print 
  185. 660 if PS=2 then centre "TYPE: COUNT ZERO" else centre "TYPE: MAD MAX"
  186.  
  187.      Print up the information.
  188.  
  189. 670 repeat 
  190.  
  191.      Set up the main loop.
  192.  
  193. 680 S=peek($FFFFFC02)
  194.  
  195.      Get the scancode of and keypress. I can't use inkey$/scancode 
  196.      'cos the rasters cut them out.
  197.  
  198. 690 doke start(8),0 : doke start(8)+2,(psg(8)/2)*$100 
  199.     : doke start(8)+4,(psg(9)/2)*$110 : doke start(8)+6,(psg(10)/2)*$101 
  200.     : doke start(8)+8,0 : doke start(8)+10,$FFFF
  201.  
  202.      Set up the colours of the rasters according to the volume of 
  203.      each voice.
  204.  
  205. 700 X=2 : for T=8 to 10 : if psg(T)=16 then doke start(8)+X,psg(X-2)*5
  206. 710 X=X+2 : next T
  207.  
  208.      If the voice is using an evolope, then est the raster to the 
  209.      colour according to the pitch of the voice.
  210.  
  211. 720 areg(0)=$FF8240 : areg(1)=start(8) : areg(2)=start(9) : dreg(0)=1 
  212.     : dreg(1)=1 : call start(15)+28
  213.  
  214.      Draw the rasters.
  215.  
  216. 730 dreg(0)=CUR : call start(10)+PS
  217.  
  218.      Play the next bit of the music.
  219.  
  220. 740 if FLS and psg(CV)<>OLDP and psg(CV)<>0 then poke $FFFF8800,14 
  221.     : poke $FFFF8802,$40
  222.  
  223.      If the drive light flag is true, then flash the drive light.
  224.  
  225. 750 if FLS and psg(CV)=OLDP or psg(CV)=0 then poke $FFFF8800,14 
  226.     : poke $FFFF8802,2
  227.  
  228.      If the drive light flag is true, but the voice is off, turn 
  229.      off the drive light.
  230.  
  231. 760 OLDP=psg(CV) : swap FLS,FLS2
  232.  
  233.      Hold the old psg level and swp the light-flag.
  234.  
  235. 770 wait vbl 
  236.  
  237.      Hrrrum...
  238.  
  239. 780 until (S>58 and S<69) or (S>83 and S<90) or (S=57) or (S>1 and S<5)
  240.  
  241.      Until you press one of these keys. (functions, space or 1-3. 
  242.      1-3 change the voice which affects the drive light).
  243.  
  244. 790 if S=57 then bell : areg(0)=$FF8240 : areg(1)=start(8) 
  245.     : areg(2)=start(9) : dreg(0)=0 : dreg(1)=1 : call start(15)+28 
  246.     : wait vbl : poke $FFFF8800,14 : poke  $FFFF8802,2 : goto 170 
  247.  
  248.      Pressed space, so disable the rasters and jump to the file-
  249.      selector.
  250.  
  251. 800 if S>1 and S<5 then CV=(S-2)+8 : goto 670
  252.  
  253.      1-3 so change the voice affecting the drive light.
  254.  
  255. 810 if S>58 and S<69 then CUR=S-58 else CUR=S-73
  256.  
  257.      A function key, so change the music number.
  258.  
  259.  
  260. 820 remCUR=F : rem> SET CUR TO FUNCTION KEY PRESSED <
  261.  
  262.      An old crap line that I forgot to remove.
  263.  
  264. 830 goto 590 
  265.  
  266.      Jump back and play it.
  267.  
  268. 850 H=hunt(start(10) to start(10)+L,"Count") 
  269.     : if H<>0 then PS=2 else PS=-1 
  270.  
  271.      Check if it's a Count Zero file and set PS if it is.
  272.  
  273. 860 if PS>0 then return 
  274.  
  275.      If PS has been set, then return.
  276.  
  277. 870 home : print "THAT DOES NOT SEEM TO BE A NORMAL"
  278. 880 print "MUSIC FILE."
  279. 890 repeat : until inkey$=" " : return 
  280.  
  281.      PS wasn't set, so it wasn't a music file (probably).
  282.  
  283. 960 areg(0)=$FF8240 : areg(1)=start(8) : areg(2)=start(9) 
  284.     : dreg(0)=0 : dreg(1)=0 : call start(15)+28 : wait vbl 
  285.  
  286.      Disable rasters (not always the best thing to do really, but 
  287.      never mind).
  288.  
  289. 970 print "ERROR!" : print "Line:";errl : print "Number:";errn : bell : end 
  290. 1000 screen copy physic to back : colour 0,0 : wait vbl 
  291.  
  292.      Blah blah...
  293.  
  294. 1010 show on : G$=file select$("*.MUS","Save a music file",8) : if G$="" then return 
  295. 1020 bsave G$,start(10) to start(10)+L
  296. 1025 dreg(0)=CUR : call start(10) : rem> PLAY MUSIC 'CUR' <
  297. 1030 hide on : wait vbl : return 
  298.  
  299.      Erm, this was (and still is I suppose) a bit to save the 
  300.      music file back out again.
  301.  
  302. note from editor: Mad max backwards is xam dam, whereas Count Zero 
  303. backwards is orez tnuoc.
  304.  
  305.